package nowcoder.huawei;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

/**
 * @author wuguojian
 * @description https://www.nowcoder.com/practice/fbc417f314f745b1978fc751a54ac8cb
 **/
public class HJ67 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new FileReader("input/nowcoder_huawei/HJ67.txt"));
//        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int[] nums = new int[4];
            boolean[] visit = new boolean[4];
            for (int i = 0; i < nums.length; i++) {
                nums[i] = in.nextInt();
            }
            System.out.println(isOk(0, nums, visit));
        }
    }

    private static boolean isOk(int amount, int[] nums, boolean[] visit) {
        if (amount == 24) {
            return true;
        }
        for (int i = 0; i < nums.length; i++) {
            if (visit[i]) {
                continue;
            }
            int num = nums[i];
            visit[i] = true;
            if (isOk(amount + num, nums, visit) ||
                    isOk(amount - num, nums, visit) ||
                    isOk(amount * num, nums, visit) ||
                    // 这里要判断一下是否整除，避免精度问题
                    (amount % num == 0 && isOk(amount / num, nums, visit))) {
                return true;
            }
            visit[i] = false;
        }
        return false;
    }
}
